package com.bootdo.common.service.impl;

import com.bootdo.common.dao.FileAttatchmentDao;
import com.bootdo.common.dao.FileDao;
import com.bootdo.common.domain.FileAttatchmentDO;
import com.bootdo.common.domain.FileDO;
import com.bootdo.common.service.FileAttatchmentService;
import com.bootdo.common.vo.AttatchmentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
public class FileAttatchmentServiceImpl implements FileAttatchmentService {
	@Autowired
	private FileAttatchmentDao fileAttatchmentDao;

	@Autowired
	private FileDao fileDao;
	
	@Override
	public FileAttatchmentDO get(String uuid){
		return fileAttatchmentDao.get(uuid);
	}
	
	@Override
	public List<FileAttatchmentDO> list(Map<String, Object> map){
		return fileAttatchmentDao.list(map);
	}

	@Override
	public List<AttatchmentVO> listAttatchmentByCid(String cid,String type) {
		List<AttatchmentVO> listRet = new ArrayList<AttatchmentVO>();
		Map<String, Object> params = new HashMap<String, Object>();
		if (null == cid || cid.equals("")){
			return listRet;
		}
		params.put("cid", cid);
		params.put("type", type);
		List<FileAttatchmentDO> list = fileAttatchmentDao.list(params);
		for (FileAttatchmentDO attatchmentDO : list) {
			AttatchmentVO aVO = new AttatchmentVO();
			aVO.setAttatchmentDO(attatchmentDO);
			FileDO fDo = fileDao.get(Long.parseLong(attatchmentDO.getFid()),type);
			if (fDo!=null){
				aVO.setFileDO(fDo);
				listRet.add(aVO);
			}

		}
		return listRet;
	}


	@Override
	public int count(Map<String, Object> map){
		return fileAttatchmentDao.count(map);
	}
	
	@Override
	public int save(FileAttatchmentDO fileAttatchment){
		return fileAttatchmentDao.save(fileAttatchment);
	}
	
	@Override
	public int update(FileAttatchmentDO fileAttatchment){
		return fileAttatchmentDao.update(fileAttatchment);
	}
	
	@Override
	public int remove(String uuid){
		return fileAttatchmentDao.remove(uuid);
	}

	@Override
	public int removeByCid(String cid) {
		// TODO Auto-generated method stub
		return fileAttatchmentDao.removeByCid(cid);
	}

	@Override
	public int removeByFid(String id) {
		// TODO Auto-generated method stub
		return fileAttatchmentDao.removeByFid(id);
	}
	@Override
	public int removeByFidAndType(String id, String type) {
		// TODO Auto-generated method stub
		return fileAttatchmentDao.removeByFidAndType(id, type);
	}

	@Override
	public int batchRemove(String[] uuids){
		return fileAttatchmentDao.batchRemove(uuids);
	}
	
}
